package com.tled.zyf.session;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet("/sessionDemo1")
public class SessionDemo_01 extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// 获取 session
		HttpSession session = req.getSession();
		session.setAttribute("count", 1);

		// 期望客户端关闭后session相同
		Cookie cookie = new Cookie("JSESSIONID", session.getId());
		cookie.setMaxAge(12356113);
		resp.addCookie(cookie);
	}
}
